﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Besture.Bll;
using Besture.Common;
using Besture.Model;

namespace Besture.UI.Portal.HelpCenter
{
    public partial class HelpCenter : System.Web.UI.Page
    {
        #region 属性
        /// <summary>
        /// 编号
        /// </summary>
        protected int Id
        {
            get
            {
                if (string.IsNullOrEmpty(StringHelper.Query("id")) && StringHelper.IsNumber(StringHelper.Query("id")))
                {
                    return 0;
                }
                return Convert.ToInt32(StringHelper.Query("id"));
            }
        }

        /// <summary>
        /// DataTable
        /// </summary>
        protected DataTable DetailDt = null;
        #endregion

        #region 初始化
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitData();
            }
        }
        #endregion

        #region 绑定数据
        /// <summary>
        /// 绑定数据
        /// </summary>
        private void InitData()
        {
            //绑定左侧导航
            var dt = QueryDac.GetTable(string.Format(@"
            SELECT * FROM dbo.TBPart
            WHERE ParentID=134 
            ORDER BY SortID ASC "));
            repHelpCenter.DataSource = dt;
            repHelpCenter.DataBind();

            if (Id==0)
            {
                //没有编号的情况下，默认取第一个栏目的内容数据
                DetailDt = QueryDac.GetTable(string.Format(@"
                SELECT pc.*,tbp.Name AS TBPName FROM dbo.TBPartContent pc
                INNER JOIN dbo.TBPart tbp ON tbp.ID=pc.PartID
                WHERE pc.PartID = (SELECT TOP 1 ID FROM dbo.TBPart tp WHERE tp.ParentID = 134 ORDER BY tp.SortID ASC )
                ORDER BY pc.SortID ASC "));
            }
            else
            {
                //根据编号获取对应的内容数据
                DetailDt = QueryDac.GetTable(string.Format(@"
                SELECT pc.*,tbp.Name AS TBPName FROM dbo.TBPartContent pc
                INNER JOIN dbo.TBPart tbp ON tbp.ID=pc.PartID
                WHERE pc.PartID = {0} 
                ORDER BY pc.SortID ASC ", Id));
            }
        }
        #endregion
    }
}